# 使用常规方式读取test.txt文件的内容。(注意文件有多行内容，都需要读取)
class Test:
    def __init__(self):
        file_path = "D:\\python-workspace\\pythonProject1\\test.txt"
        self.file_path = file_path

    def read1_file(self):
        file1 = open(self.file_path, "r", encoding="utf-8")
        print(file1.read())
        file1.close()

    # 向目标文件写入内容“1234567890”
    def write1_file(self):
        file2 = open(self.file_path, "w", encoding="utf-8")
        file2.write("hello world")
        file2.close()

    # 向目标文件追加内容“asdfghjkl”
    def add_file(self):
        f = open(self.file_path, "a", encoding="utf-8")
        f.write("asdfghjkl"+'\n')
        f.close()

    # 5、使用with open打开文件并且读取文件内容
    def read2_file(self):
        with open(self.file_path, "r", encoding="utf-8") as file:
            print(file.read())


if __name__ == '__main__':
    test = Test()
    test.read2_file()
